package lanou.giftsay_01.thread;

import android.os.Handler;
import android.os.Message;
import android.support.v4.view.ViewPager;
import android.util.Log;

/**
 * Created by dllo on 16/8/17.
 */
public class SleepThread implements Runnable{
    private Handler handler;

    private ViewPager viewPager;

    private boolean flag = true;

    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    public SleepThread(Handler handler, ViewPager viewPager) {
        this.handler = handler;
        this.viewPager = viewPager;
    }

    @Override
    public void run() {
        while (flag) {
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();

            }
            Log.d("SleepThread", "run");
           // Message message = handler.obtainMessage();
            //message.what =  viewPager.getCurrentItem();
            handler.sendEmptyMessage(viewPager.getCurrentItem());
            //handler.sendMessageDelayed(message , 2000);
        }
    }


}
